package com.shelpe.services.lexicon.service.tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shelpe.services.lexicon.entity.AdgroupRecord;
import com.shelpe.services.lexicon.entity.KeywordRecommend;
import com.shelpe.services.lexicon.entity.KeywordTag;
import com.shelpe.services.lexicon.repository.mongo.AdgroupRecordRepository;

@Service
/**
 * 精确包规则
 * @author Otis
 *
 */
public class PertinenceRecommendTagRule implements RecommendTagRule {

	
	@Autowired
	private AdgroupRecordRepository adgroupRecordRepository;
	
	@Override
	public KeywordTag tag(KeywordRecommend word,TagRuleContext context) {
		KeywordTag tag = null;
		
		boolean satisfied = word.getMetric() != null;
		satisfied = satisfied && word.getMetric().getPertinence() >= 3;
		
		if(word.getInsight() != null){
			AdgroupRecord record = this.adgroupRecordRepository.findOne(word.getAdgroupRecordID());
			satisfied = satisfied && word.getInsight().getClick() >= (record.getClick()>0?record.getClick(): 1000);
			satisfied = satisfied && word.getInsight().getImpression() >= 200;
		}else{
			satisfied = false;
		}
		
		if(satisfied){
			tag = new KeywordTag();
			tag.setTagID(1);
			tag.setTagName("precise");
		}
		return tag;
	}

	
}
